<template>
	<view>
		<view v-if="hasCanPlay" class="fab-box fab" :class="{
				rightBottom: true
			}"  :style="'bottom:'+viewY+'px;'"
			@touchstart="drag_start" @touchmove.stop.prevent="drag_hmove" >
			<view class="fab-circle" :class="{
					bottom: true,
					right: true
				}"
			 :style="{ 'background-color': styles.buttonColor }" @click="_onClick">
				<text class="iconfont icon-play" v-if="!isPlaying"></text>
				<text class="iconfont icon-zantinganniu" v-if="isPlaying"></text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex'
	export default {
		computed: {
			...mapState(['isPlaying']),
		},
		props: {
			show: {
				type: Boolean,
				default: false
			},
			hasCanPlay:false,
			isParentClickEvent:false,
		},
		onShow(){
		},
		data() {
			return {
				fabShow: false,
				flug: true,
				styles: {
					color: '#3c3e49',
					selectedColor: '#007AFF',
					backgroundColor: '#fff',
					buttonColor: '#3c3e49'
				},
				start:0,
				viewY:130,
				startY:0,
				moveY:0,
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor:"#007AFF"
				},
			};
		},
		created() {
			if (this.top === 0) {
				this.fabShow = true;
			}
			// 初始化样式
			this.styles = Object.assign({}, this.styles, this.pattern);
			this.viewY = uni.upx2px(130);
		},
		methods: {
			_onClick() {
				if(!this.$store.state.music){
					return;
				}
				if(this.isParentClickEvent){
					if(this.$store.state.music.paused && this.$store.state.preludeMusic.paused){
						this.$emit('play');
					}else{
						this.$emit('pause');
					}
					return;
				}
				console.log(this.$store.state.music.paused + "==============" + this.$store.state.preludeMusic.paused)
				if(this.$store.state.music.paused && this.$store.state.preludeMusic.paused){
					this.$store.commit("SET_IS_PRELUDE_MUSIC_FINISHED", true);
					this.$store.state.music.play();
					this.$store.commit("SET_PLAYING", true);
				}else{
					if(!this.$store.state.preludeMusic.paused){
						this.$store.state.preludeMusic.pause();
					}
					if(!this.$store.state.music.paused){
						this.$store.state.music.pause();
					}
					this.$store.commit("SET_PLAYING", false);
				}
			},
			/**
			 * 按钮点击事件
			 */
			_onItemClick(index, item) {
				this.$emit('trigger', {
					index,
					item
				});
			},
			drag_start(event){
				this.start= event.touches[0].clientY;
				this.startY = this.viewY;
				console.log("drag_start:" + this.start);
			},
			drag_hmove(event){
				let	 tag 	 = event.touches;
				this.viewY	 = this.startY - tag[0].clientY+this.start;
				console.log("drag_hmove:" + tag[0].clientY +"====" +(tag[0].clientY-this.start) + "====moveY:"+this.moveY );
			},
		},
		watch: {
			pattern(newValue, oldValue) {
				console.log(JSON.stringify(newValue));
				this.styles = Object.assign({}, this.styles, newValue);
			}
		},
	};
</script>

<style scoped>
	.fab-box {
		position: fixed;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 2;
	}

	.fab-box.top {
		width: 60upx;
		height: 60upx;
		right: 30upx;
		bottom: 60upx;
		border: 1px #5989b9 solid;
		background: #6699cc;
		border-radius: 10upx;
		color: #fff;
		transition: all 0.3;
		opacity: 0;
	}

	.fab-box.active {
		opacity: 1;
	}

	.fab-box.fab {
		z-index: 10;
	}

	.fab-box.fab.leftBottom {
		left: 30upx;
		bottom: 120upx;
	}

	.fab-box.fab.leftTop {
		left: 30upx;
		top: 80upx;
		/* #ifdef H5 */
		top: calc(80upx + var(--window-top));
		/* #endif */
	}

	.fab-box.fab.rightBottom {
		right: 30upx;
	}

	.fab-box.fab.rightTop {
		right: 30upx;
		top: 80upx;
		/* #ifdef H5 */
		top: calc(80upx + var(--window-top));
		/* #endif */
	}

	.fab-circle {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		width: 80upx;
		height: 80upx;
		background: #3c3e49;
		/* background: #5989b9; */
		border-radius: 50%;
		box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.2);
		z-index: 11;
	}

	.fab-circle.left {
		left: 0upx;
	}

	.fab-circle.right {
		right: 0upx;
	}

	.fab-circle.top {
		top: 0upx;
	}

	.fab-circle.bottom {
		bottom: 0upx;
	}

	.fab-circle .uni-icon-plusempty {
		color: #ffffff;
		font-size: 58upx;
		transition: all 0.3s;
		font-weight: bold;
	}

	.fab-circle .uni-icon-plusempty.active {
		transform: rotate(135deg);
	}
</style>
